@echo off
echo "==>TAO_ROOT=%TAO_ROOT%"

set PROJECT_PATH="%TAO_ROOT%/orbsvcs/tests/FT_App"

cd %PROJECT_PATH%


@echo off
setlocal

:: 定义要删除的文件列表
set "files=*.ior"

:: 删除文件
for %%f in (%files%) do (
    if exist "%%f" (
        echo Deleting %%f...
        del "%%f"
        if not errorlevel 1 (
            echo Deleted %%f successfully.
        ) else (
            echo Error deleting %%f.
        )
    ) else (
        echo %%f does not exist. Skipping.
    )
)


@REM 启动命名服务
start "tao_cosnaming" cmd /k "%TAO_ROOT%/orbsvcs/Naming_Service/tao_cosnaming -ORBdebuglevel -o %PROJECT_PATH%/ns.ior -m 1"
timeout /t 3

@REM 启动复制管理器 -n 指定绑定到命名服务的名称
start "tao_ft_replicationmanager" cmd /k "%TAO_ROOT%/orbsvcs/FT_ReplicationManager/tao_ft_replicationmanager -o %PROJECT_PATH%/rm.ior -ORBEndpoint iiop://OMEN_2023:17539 -n ReplicationManager"
timeout /t 4

@REM 启动故障检测器
echo "==>Start tao_fault_notifier"
start "tao_fault_notifier" cmd /k "%TAO_ROOT%/orbsvcs/Fault_Notifier/tao_fault_notifier -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o %PROJECT_PATH%/notifier.ior -q"
timeout /t 5

@REM 启动故障检测器1,注册到 复制管理器上
echo "==>Start tao_fault_detector"
start "tao_fault_detector" cmd /k "%TAO_ROOT%/orbsvcs/Fault_Detector/tao_fault_detector -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o %PROJECT_PATH%/detector1.ior -l shire -q"
timeout /t 5

@REM 启动故障检测器2,注册到 复制管理器上
echo "==>Start tao_fault_detector"
start "tao_fault_detector" cmd /k "%TAO_ROOT%/orbsvcs/Fault_Detector/tao_fault_detector -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o %PROJECT_PATH%/detector1.ior -l bree -q"
timeout /t 5

@REM @REM =======================

echo "==>Start ft_replica1"
start "ft_replica1" cmd /k "ft_replica -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o %PROJECT_PATH%/factory1.ior -l shire -i hobbit -q -p %PROJECT_PATH%/persistent.dat
"
timeout /t 8

echo "==>Start ft_replica2"
start "ft_replica2" cmd /k "ft_replica -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o %PROJECT_PATH%/factory2.ior -l bree -i hobbit -i elf -q -p %PROJECT_PATH%/persistent.dat" 
timeout /t 8

echo "==>Start ft_replica3"
start "ft_replica3" cmd /k "ft_replica -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o %PROJECT_PATH%/factory3.ior -l rivendell -i elf -q -p %PROJECT_PATH%/persistent.dat" 
timeout /t 8


echo "==>Start ft_create"
start "ft_create" cmd /k "ft_create -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -n -r hobbit -r elf -r hobbit -i"
timeout /t 8

sleep(30);
@REM client
echo "==>Start ft_client"
start "ft_client1" cmd /k "ft_client -f file://%PROJECT_PATH%/hobbit_shire_0.ior -f file://%PROJECT_PATH%/hobbit_bree_0.ior -c testscript"
timeout /t 20

echo "==>Start ft_client"
start "ft_client2" cmd /k "ft_client -f file://%PROJECT_PATH%/elf_bree_1.ior -f file://%PROJECT_PATH%/elf_rivendell_0.ior -c testscript"
timeout /t 20

echo "==>Start ft_client"
start "ft_client3" cmd /k "ft_client -f file://%PROJECT_PATH%/hobbit_shire_1.ior -f file://%PROJECT_PATH%/hobbit_bree_2.ior -c testscript"
timeout /t 20
pause >nul
@echo off


@REM ==================替换命令
@REM start %TAO_ROOT%/orbsvcs/FT_ReplicationManager/tao_ft_replicationmanager -o %PROJECT_PATH%/rm.ior -ORBEndpoint iiop://OMEN_2023:17539
@REM start %TAO_ROOT%/orbsvcs/Fault_Notifier/tao_fault_notifier -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o %PROJECT_PATH%/notifier.ior -q
@REM start %TAO_ROOT%/orbsvcs/Fault_Detector/tao_fault_detector -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o %PROJECT_PATH%/detector1.ior -l shire -q
@REM start %TAO_ROOT%/orbsvcs/Fault_Detector/tao_fault_detector -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o %PROJECT_PATH%/detector1.ior -l bree -q
@REM start ./ft_replica -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o %PROJECT_PATH%/factory1.ior -l shire -i hobbit -q -p %PROJECT_PATH%/persistent.dat
@REM start ./ft_replica -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o %PROJECT_PATH%/factory2.ior -l bree -i hobbit -i elf -q -p %PROJECT_PATH%/persistent.dat
@REM start ./ft_replica -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o %PROJECT_PATH%/factory3.ior -l rivendell -i elf -q -p %PROJECT_PATH%/persistent.dat
@REM start ./ft_create -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -n -r hobbit -r elf -r hobbit -u  -i
@REM start ./ft_client -f file://%PROJECT_PATH%/hobbit_shire_0.ior -f file://%PROJECT_PATH%/hobbit_bree_0.ior -c testscript
@REM start ./ft_client -f file://%PROJECT_PATH%/elf_bree_1.ior -f file://%PROJECT_PATH%/elf_rivendell_0.ior -c testscript
@REM start ./ft_client -f file://%PROJECT_PATH%/hobbit_shire_1.ior -f file://%PROJECT_PATH%/hobbit_bree_2.ior -c testscript

@REM --------------------不模拟故障
@REM start ./ft_create -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -n -r hobbit -r elf -r hobbit -u  -g
@REM start ./ft_client -f file://%PROJECT_PATH%/hobbit_0.iogr -c testscript
@REM start ./ft_client -f file://%PROJECT_PATH%/elf_1.iogr -c testscript
@REM start ./ft_client -f file://%PROJECT_PATH%/hobbit_2.iogr -c testscript
@REM start ./replmgr_controller -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -x


@REM ==================原始命令
@REM start E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/FT_ReplicationManager/tao_ft_replicationmanager -o E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/rm.ior -ORBEndpoint iiop://OMEN_2023:17539
@REM start E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/Fault_Notifier/tao_fault_notifier -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/notifier.ior -q
@REM start E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/Fault_Detector/tao_fault_detector -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/detector1.ior -l shire -q
@REM start E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/Fault_Detector/tao_fault_detector -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/detector1.ior -l bree -q
@REM start ./ft_replica -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/factory1.ior -l shire -i hobbit -q -p E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/persistent.dat
@REM start ./ft_replica -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/factory2.ior -l bree -i hobbit -i elf -q -p E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/persistent.dat
@REM start ./ft_replica -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -o E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/factory3.ior -l rivendell -i elf -q -p E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/persistent.dat
@REM start ./ft_create -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -n -r hobbit -r elf -r hobbit -u  -i
@REM start ./ft_client -f file://E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/hobbit_shire_0.ior -f file://E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/hobbit_bree_0.ior -c testscript
@REM start ./ft_client -f file://E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/elf_bree_1.ior -f file://E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/elf_rivendell_0.ior -c testscript
@REM start ./ft_client -f file://E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/hobbit_shire_1.ior -f file://E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/hobbit_bree_2.ior -c testscript

@REM --------------------不模拟故障
@REM start ./ft_create -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -n -r hobbit -r elf -r hobbit -u  -g
@REM start ./ft_client -f file://E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/hobbit_0.iogr -c testscript
@REM start ./ft_client -f file://E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/elf_1.iogr -c testscript
@REM start ./ft_client -f file://E:/_proj/_opendds/ACE_wrappers/TAO/orbsvcs/tests/FT_App/hobbit_2.iogr -c testscript
@REM start ./replmgr_controller -ORBInitRef ReplicationManager=corbaloc::OMEN_2023:17539/ReplicationManager -x
